#ifndef _HAL_NVS_H_
#define _HAL_NVS_H_

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief           nvs write.
 * @param namespace Namespace name.
 * @param key       Key name.
 * @param data      The value to set.
 * @param len       Length of binary value to set, in bytes.
 * @return     - ESP_OK if storage handle was opened successfully
 *             - ESP_FAIL if there is an internal error; most likely due to corrupted
 *               NVS partition (only if NVS assertion checks are disabled)
 *             - ESP_ERR_NVS_NOT_INITIALIZED if the storage driver is not initialized
 *             - ESP_ERR_NVS_PART_NOT_FOUND if the partition with label "nvs" is not found
 *             - ESP_ERR_NVS_NOT_FOUND id namespace doesn't exist yet and
 *               mode is NVS_READONLY
 *             - ESP_ERR_NVS_INVALID_NAME if namespace name doesn't satisfy constraints
 *             - ESP_ERR_NO_MEM in case memory could not be allocated for the internal structures
 *             - ESP_ERR_NVS_NOT_ENOUGH_SPACE if there is no space for a new entry or there are too many different
 *                                  namespaces (maximum allowed different namespaces: 254)
 *             - ESP_ERR_NOT_ALLOWED if the NVS partition is read-only and mode is NVS_READWRITE
 *             - ESP_ERR_INVALID_ARG if out_handle is equal to NULL
 *             - other error codes from the underlying storage driver
 */
int hal_nvs_set_blob(const char *namespace, const char *key, const void *data, size_t len);

/**
 * @brief           nvs read.
 * @param namespace Namespace name.
 * @param key       Key name.
 * @param data      The value to read.
 * @param len       Length of binary value to read, in bytes.
 * @return     - ESP_OK if storage handle was opened successfully
 *             - ESP_FAIL if there is an internal error; most likely due to corrupted
 *               NVS partition (only if NVS assertion checks are disabled)
 *             - ESP_ERR_NVS_NOT_INITIALIZED if the storage driver is not initialized
 *             - ESP_ERR_NVS_PART_NOT_FOUND if the partition with label "nvs" is not found
 *             - ESP_ERR_NVS_NOT_FOUND id namespace doesn't exist yet and
 *               mode is NVS_READONLY
 *             - ESP_ERR_NVS_INVALID_NAME if namespace name doesn't satisfy constraints
 *             - ESP_ERR_NO_MEM in case memory could not be allocated for the internal structures
 *             - ESP_ERR_NVS_NOT_ENOUGH_SPACE if there is no space for a new entry or there are too many different
 *                                  namespaces (maximum allowed different namespaces: 254)
 *             - ESP_ERR_NOT_ALLOWED if the NVS partition is read-only and mode is NVS_READWRITE
 *             - ESP_ERR_INVALID_ARG if out_handle is equal to NULL
 *             - other error codes from the underlying storage driver
 */
int hal_nvs_get_blob(const char *namespace, const char *key, void *data, size_t len);

/**
 * @brief           nvs erase key.
 * @param namespace Namespace name.
 * @param key       Key name.
 * @return     - ESP_OK if storage handle was opened successfully
 *             - ESP_FAIL if there is an internal error; most likely due to corrupted
 *               NVS partition (only if NVS assertion checks are disabled)
 */
int hal_nvs_erase_key(const char *namespace, const char *key);

#ifdef __cplusplus
}
#endif

#endif //_HAL_NVS_H_
